package com.gxa.clientproduct.service.impl;

import com.gxa.clientproduct.mapper.CommentMapper;
import com.gxa.clientproduct.pojo.Comment;
import com.gxa.clientproduct.service.CommentService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;


/**
 * @Author: fenglin
 * @Date:2020/11/12 14:38
 * @Version 1.0
 */
@Service("commentService")
public class CommentServiceImpl implements CommentService {

    @Resource
    CommentMapper commentMapper=null;

    @Override
    public List<Comment> commFindAll() {
        return commentMapper.selectAll();
    }

    @Override
    public List<Comment> commFindName(Comment comment) {
        Example example = new Example(Comment.class);
        Example.Criteria criteria = example.createCriteria();
        if (comment.getContent()!=null){
        criteria.andLike("content","%"+comment.getContent()+"%");
        }
        return commentMapper.selectByExample(example);
    }

    @Override
    public int commStateAndRecd(Comment comment) {

        Example example = new Example(Comment.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("id",comment.getId());


        return commentMapper.updateByExampleSelective(comment,example);
    }

    @Override
    public int commDelete(Comment comment) {
        return commentMapper.delete(comment);
    }

    @Override
    public int commAdd(Comment comment) {
        return commentMapper.insertSelective(comment);
    }
}
